package dao;

import net.sf.json.JSONArray;

import org.springframework.stereotype.Component;

import support.GridResult;
import dao.support.sql.SqlObject;
import model.data.DataDictionary;
import model.data.Product;

@Component
public class ProductDao extends BaseDao {
	public void product_add(Product product)
	{
		this.create(product);
	}
	public void product_delete(String product_id)
	{
		Object []list = JSONArray.fromObject(product_id).toArray();
		for(Object obj : list)
		{
			String s = obj.toString();
			this.delete(Integer.parseInt(s), Product.class);
		}
	}
	public Product product_foundbyid(String product_id)
	{
		int id = Integer.parseInt(product_id);
		return (Product) super.loadById(id, Product.class);
	}
	public void product_update(Product product)
	{
		this.update(product);
	}
	public String product_query(SqlObject so)
	{
		Object obj = this.querySQLRead(so.getSqlCount()).get(0).get("c");
		int total = Integer.parseInt(obj.toString());
		return new GridResult(so.getPage(), (total-1)/so.getRows()+1, total, this.querySQLRead(so.getSqlRows())).toString();
	}
}